package com.sgb.kjwl.view.ui.adapter.transport;

import android.text.Html;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.common.AddressItem;
import com.sgb.kjwl.utils.DefaultUtil;

import java.util.List;

/**
 * @author: 杨畔
 * @date: 3/9/21 3:07 PM
 * @Description: 装卸地适配器
 */
public class LoadingAndUnloadingPlaceAdapter extends BaseQuickAdapter<AddressItem, BaseViewHolder> {
    private int mIndex = -1;

    public LoadingAndUnloadingPlaceAdapter(@Nullable List<AddressItem> data) {
        super(R.layout.item_loading_and_unloading_place, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AddressItem item) {
        helper.setText(R.id.tv_loading_and_unloading_place_location, DefaultUtil.getString(item.getAddressName()))
                .setText(R.id.tv_loading_and_unloading_place_address, Html.fromHtml(String.format("%s%s",
                        !TextUtils.isEmpty(item.getDistance())
                                ? String.format("<font color=\"#5792FD\">%skm</font> ", item.getDistance())
                                : "",
                        DefaultUtil.getString(item.getAddressdetail()))))
                .setImageResource(R.id.iv_loading_and_unloading_place, item.getIcon())
                .setVisible(R.id.tv_loading_and_unloading_place_go, helper.getLayoutPosition() == mIndex)
                .addOnClickListener(R.id.tv_loading_and_unloading_place_go);
    }

    public void setIndex(int mIndex) {
        this.mIndex = mIndex;
    }
}
